import org.apache.spark.rdd.RDD
import org.apache.spark.sql.{DataFrame, Dataset, Row, SparkSession}
import org.apache.spark.{SparkConf, SparkContext}


object DataFrameTODataSet {

    def main(args: Array[String]): Unit = {
        val sparkConf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("XXX")
        val sparkSession: SparkSession = SparkSession.builder().config(sparkConf).getOrCreate()
        val sparkContext: SparkContext = sparkSession.sparkContext
        import sparkSession.implicits._

        val rdd: RDD[(String, Int)] = sparkContext.makeRDD(List(("zz",20),("ww",20)))
        rdd.foreach(println)

        val dataFrame: DataFrame = rdd.toDF("name","age")
        dataFrame.show()

        val dataSet: Dataset[People] = dataFrame.as[People]
        dataSet.show()

        val df: DataFrame = dataSet.toDF()
        df.show()

        val rdd1: RDD[Row] = df.rdd
        rdd1.foreach(println)

    }

}
case class People(name:String,age:Int)
